package _17_剑指Offer;

public class _63_剑指Offer股票的最大利润 {

    public static void main(String[] args) {

        _63_剑指Offer股票的最大利润 v = new _63_剑指Offer股票的最大利润();

        int[] ins = new int[]{7, 1, 5, 3, 6, 4};
        System.out.println(v.maxProfit(ins));

    }

    public int maxProfit(int[] prices) {
        if (prices.length == 0) return 0;
        int min = prices[0];
        int maxProfit = 0;
        for (int i = 1; i < prices.length; i++) {
            if (prices[i] > min) {
                maxProfit = Math.max(maxProfit, prices[i] - min);
            }
            min = Math.min(min, prices[i]);
        }
        return maxProfit;
    }

}
